package com.prototype.deepshallowCopy;

/**
 * 看一下 原型对象中，如果有一个属性是引用类型
 * 在克隆的时候，这个引用类型是深拷贝还是浅拷贝
 */
public class TestDeepShallowCopy {
    public static void main(String[] args) {

        People people = new People("Tom" , 21 );
        //单独为people的friend属性赋值
        people.setFriend(new People("Jake" , 11));

        People people1 = (People) people.clone();
        People people2 = (People) people.clone();
        People people3 = (People) people.clone();
        People people4 = (People) people.clone();

        System.out.println(people);
        System.out.println(people1);
        System.out.println(people2);
        System.out.println(people3);
        System.out.println(people4);

        //检查拷贝出来的对象的 friend属性是不是同一个对象
        System.out.println(people.getFriend().hashCode());
        System.out.println(people1.getFriend().hashCode());
        System.out.println(people2.getFriend().hashCode());
        //true
        System.out.println(people1.getFriend() == people2.getFriend());

    }
}
